package com.example.myapplication3;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class LoginActivity extends AppCompatActivity {

    private EditText editTextUsername, editTextPassword;
    private Button ButtonLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        editTextUsername = findViewById(R.id.editTextUsername);
        editTextPassword = findViewById(R.id.editTextPassword);
        ButtonLogin = findViewById(R.id.ButtonLogin);

        ButtonLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String username = editTextUsername.getText().toString().trim();
                String password = editTextPassword.getText().toString().trim();

                // TODO: Implement your login logic here
                // For now, we'll just show a Toast message
                Toast.makeText(LoginActivity.this, "Logging in: " + username, Toast.LENGTH_SHORT).show();
            }
        });
        // 设置下页按钮的点击事件
        ButtonLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 获取输入框的数据
                String username = editTextUsername.getText().toString();
                String password = editTextPassword.getText().toString();
                // 创建Intent传递数据到下一个Activity
                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                intent.putExtra("username", username);
                intent.putExtra("password", password);
                // 添加转场动画
                overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);

                // 启动下一个Activity
                startActivity(intent);
            }
        });
    }}

